package com.serve.oa.controller;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import java.time.Duration;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Function;
import java.util.stream.Collectors;


@Data
@AllArgsConstructor
@NoArgsConstructor
class User {
    private int id;
    private String email;


    // getters and setters
}

@Data
@AllArgsConstructor
@NoArgsConstructor
class UserInfo {
    private int userId;
    private String emailsss;
    // getters and setters
}


public class Drxt {
    List<User> convertUsersToUserInfos(List<User> users) {
       // return users.stream().map(user->new UserInfo(user.getId(),user.getName())).collect(Collectors.toList());
        return users.stream()
                .collect(Collectors.toMap(User::getEmail, Function.identity(), (existing, replacement) -> existing))
                .values()
                .stream()
                .collect(Collectors.toList());

    }
    @Test
    public void test() {

/*        List<User> users = new ArrayList<>();
        users.add(new User(1,"A"));
        users.add(new User(3,"B"));
        users.add(new User(2,"B"));
        users.add(new User(4,"D"));
//


        List<User> sortedUsers =  users.stream().sorted(Comparator.comparing(User::getId).reversed()).collect(Collectors.toList());
        sortedUsers.forEach(System.out::println);*/
//
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        Runnable a = new Runnable() {
            @Override
            public void run() {
                System.out.println("A");
                executorService.execute(this::run);
            }
        };
        Runnable b = new Runnable() {
            @Override
            public void run() {
                System.out.println("B");
                executorService.execute(this::run);
            }
        };
        Runnable c = new Runnable() {
            @Override
            public void run() {
                System.out.println("C");
                executorService.execute(this::run);
            }
        };
        executorService.execute(a);
        executorService.execute(b);
        executorService.execute(c);



    }
}


